package com.chrray.position.service.position.impl;
import com.chrray.position.entity.position.SysRole;
import com.chrray.position.mapper.position.SysRoleMapper;
import com.chrray.position.service.position.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.Page;
import com.chrray.position.util.result.ResponseResult;
import tk.mybatis.mapper.entity.Example;
import org.springframework.transaction.annotation.Transactional;

import static com.chrray.position.util.result.ResponseResults.success;

/**
 *系统角色
 */
@Service
public class SysRoleServiceImpl  implements ISysRoleService {
	 @Autowired
	 private SysRoleMapper  sysRoleMapper; 
	/**
	 * 查询全部 系统角色
	 */
	 @Override
	 public ResponseResult selectAll(SysRole entity){
		PageHelper.startPage(entity.getPage(),entity.getRows());
 		Example example = Example.builder(SysRole.class).build();
 		Page<SysRole> list =  (Page<SysRole>)sysRoleMapper.selectByExample(example);
		return success(list);
	}

	/**
	 * 根据ID查询 系统角色
	 */
	 @Override
	 public ResponseResult selectById(SysRole obj){
          return success(sysRoleMapper.selectByPrimaryKey(obj),"查询系统角色数据成功");
      }

	/**
	 * 添加数据系统角色
	 */
	 @Override
	 public ResponseResult insert(SysRole obj) {
 		sysRoleMapper.insertSelective(obj);
		return success("添加系统角色数据成功");
      }

	/**
	 * 修改系统角色
	 */
	 @Override
	 @Transactional(rollbackFor = Exception.class) 
	 public ResponseResult updateById(SysRole obj) {
 		int num = sysRoleMapper.updateByPrimaryKeySelective(obj);
  		return  success("修改系统角色数据成功");
	}
}